/*

  异步编程：使用 Future 和 async-await
  https://dart.cn/codelabs/async-await

 */

//Dart异步编程
Future<void>fetchUserOrder(){
  return Future.delayed(const Duration(seconds: 2),() => print('Large Latte'));
}

Future<String>fetchUserOrder2(){
  return Future.delayed(const Duration(seconds: 2), () => 'Large Latte');
}

Future<String>fetchUserOrder3() => Future.delayed(const Duration(seconds: 2), () =>'Large Latte');


String createOrderMessage(){
  var order = fetchUserOrder3();
  return 'Your order is: $order';
}

//Example: asynchronous functions
Future<String> createOrderMessage2() async{
  var order = await fetchUserOrder3();
  return 'Your order is: $order';
}

Future<void> main() async{
  print('Fetching user order...');
  print(await createOrderMessage2());
  //Fetching user order...
  // Your order is: Large Latte

}

// void main(){
//   print('---------------------------------------------------------------------');
//
//   // fetchUserOrder();
//   // print('Fetching user order...');
//   //Fetching user order...
//   // Large Latte
//
//
//   print('Fetching user order...');
//   print(createOrderMessage());
//   //Fetching user order...
//   // Your order is: Instance of 'Future<String>'
//
// }
